﻿using System;
using JetBrains.Annotations;
using JetBrains.ReSharper.Psi;
using JetBrains.ReSharper.Psi.Resolve;
using JetBrains.ReSharper.Psi.Xaml.Impl.Resolve;

namespace GammaJul.ReSharper.GammaXaml.Psi.Resolve {

	/// <summary>
	/// Symbol filter that filters on a return type.
	/// </summary>
	public class ReturnTypeFilter : SimpleSymbolFilterWithErrorType {
		private readonly IType _returnType;

		public override bool Accepts(IDeclaredElement declaredElement, ISubstitution substitution) {
			var parametersOwner = declaredElement as IParametersOwner;
			return parametersOwner != null && Equals(parametersOwner.ReturnType, _returnType);
		}
		
		/// <summary>
		/// Initializes a new instance of the <see cref="ReturnTypeFilter"/> class.
		/// </summary>
		/// <param name="returnType">The return type that a declared element must have to pass the filter.</param>
		public ReturnTypeFilter([NotNull] IType returnType)
			: base(XamlResolveErrorType.BAD_SIGNATURE) {
			if (returnType == null)
				throw new ArgumentNullException("returnType");
			_returnType = returnType;
		}
	}

}